package {
    
    // import com.viil.ViilApp;
    // import com.viil.events.ViilEvent;
    // import com.viil.structs.ExternalEventName;
    // import com.viil.structs.ExternalErrorEventName;
    // import com.viil.Base64;

    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.external.ExternalInterface;
    import flash.geom.Rectangle;
    import flash.system.Security;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.utils.ByteArray;
    import flash.utils.Timer;
    import flash.utils.setTimeout;

    import flash.media.SoundMixer;
    import flash.media.SoundTransform;
    import flash.media.Video;

    [SWF(backgroundColor="#000000", frameRate="60", width="480", height="270")]
    public class Viil extends Sprite {

        private _src:String;

        public function Viil () {
            onAddedToStatge();
        }

        private function onAddedToStatge () :void {
            stage.addEventListener(MouseEvent.CLICK, onStageClick);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
        }

        private function init () :void {
            Security.allowDomain("*");
            Security.allowInsecureDomain("*");

            if (ExternalInterface.available) {
                registerExternalMethods();
            }
        }

        private function registerExternalMethods () :void {
            ExternalInterface.marshallExceptions = true;
            try {
                ExternalInterface.addCallback('src', onSrcCalled);
                ExternalInterface.addCallback('load', onLoadCalled);
                ExternalInterface.addCallback('play', onPlayCalled);
                ExternalInterface.addCallback('pause', onPauseCalled);
                ExternalInterface.addCallback('resume', onResumeCalled);
            }
            catch (e: SecurityError) {
                if (
                    loaderInfo.parameters.debug != undefined &&
                    loaderInfo.parameters.debug == "true"
                ) {
                    throw new SecurityError(e.message);
                }
            }
            catch (e: Error) {
                if (
                    loaderInfo.parameters.debug != undefined &&
                    loaderInfo.parameters.debug == "true"
                ) {
                    throw new Error(e.message);
                }
            }
        }

        private function onSrcCalled (pSrc:* = "") :void {
            _src = String(pSrc);
        }

        private function onLoadCalled () :void {

        }

        private function onPlayCalled () :void {

        }

        private function onPauseCalled () :void {

        }

        private function onResumeCalled () :void {

        }

        private function onStageClick (e: MouseEvent) :void {

        }
    }
}